package report_file

import (
	"encoding/json"
	"fmt"
	"io/ioutil"
)

func readFile() {
	filePath := "/data/report/new_sp/campaigns/20220805/20220805_2637586688575375_P5Z"
	conJson, err := ioutil.ReadFile(filePath)

	con := make([]map[string]interface{}, 0)

	err = json.Unmarshal(conJson, &con)

	if err != nil {
		fmt.Println(err)
		return
	}

	var (
		cost float64
		sales float64
		orders float64
	)

	for _, item := range con {
		cost += item["cost"].(float64)
		sales += item["attributedSales7d"].(float64)
		orders += item["attributedUnitsOrdered7d"].(float64)
	}

	str := fmt.Sprintf("cost:%v,sales:%v,orders:%v", cost, sales, orders)
	fmt.Println(str)
	//fmt.Println(len(con), con)


	//fmt.Println(string(conJson), err)

}


